package com.company.vmvp.api;


import com.company.vmvp.ui.main.entity.CheckVersionBean;
import com.company.vmvp.ui.home.entity.NewsBean;
import com.company.vmvp.ui.main.entity.UserBean;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 * 作者：kkan on 2017/11/30
 * 当前类注释:
 * 请求地址
 * Query、QueryMap：//用于Http Get请求传递参数
 * Field、FieldMap：//用于Post方式传递参数,需要在请求接口方法上添加@FormUrlEncoded,即以表单的方式传递参数
 * Body： //用于Post,根据转换方式将实例对象转化为对应字符串传递参数.
 *         //比如Retrofit添加GsonConverterFactory则是将body转化为gson字符串进行传递
 * Path： //用于URL上占位符
 * Part、PartMap： //配合@Multipart使用,一般用于文件上传
 * Header：//添加http header
 * Headers：//跟@Header作用一样,只是使用方式不一样,@Header是作为请求方法的参数传入,@Headers是以固定方式直接添加到请求方法上POST请求
 *
 * 参考 https://blog.csdn.net/u010566681/article/details/52105536
 */
public interface HttpUrlService {

    //版本更新
    @GET("system/checkVersion")
    Observable<ResultEntity<CheckVersionBean>> checkVersion(@QueryMap Map<String, String> map);

    @FormUrlEncoded
    @POST("system/login")
    Observable<ResultEntity<UserBean>> getLogin(@FieldMap Map<String, String> map);

    @FormUrlEncoded
    @POST("system/getUserData")
    Observable<ResultEntity<UserBean>> getUserData(@FieldMap Map<String, String> map);

    @FormUrlEncoded
    @POST("system/registUser")
    Observable<ResultEntity<UserBean>> registUser(@FieldMap Map<String, String> map);

    @FormUrlEncoded
    @POST("system/getCaptcha")
    Observable<ResultEntity<UserBean>> getCaptcha(@FieldMap Map<String, String> map);

    @FormUrlEncoded
    @POST("system/getWangYiNews")
    Observable<ResultEntity<NewsBean>> getWangYiNews(@FieldMap Map<String, String> map);

    /***示例***/
    @GET("system/xxxx")
    Observable<ResultEntity<CheckVersionBean>> get1(@QueryMap Map<String, String> map);

    @GET("system/xxxxx")
    Observable<ResultEntity<UserBean>> get2(@Header("cookie") String session, @Query("name") String name);

    @FormUrlEncoded
    @POST("system/xxxxx")
    Observable<ResultEntity<UserBean>> post1(@Field("data") String data, @Field("deviceToken") String deviceToken);

    //POST文件上传
    @FormUrlEncoded
    @Headers({"Content-Type: application/json", "Accept: application/json"})
    @POST("system/xxxxx")
    Observable<ResultEntity<List<UserBean>>> post2(@PartMap Map<String, RequestBody> params, @Part("password") RequestBody password);

    @Multipart
    @POST("system/xxxxx")
    Observable<ResultEntity<UserBean>> post3(@Part MultipartBody.Part photo);

    //apk下载
    @Streaming
    @GET
    Observable<ResponseBody> download(@Url String url);
}
